var app = getApp();
var http_service = app.data.service;
const date = new Date()
const years = []
const months = []
const days = []
const hours = ['00:00']
const minutes = ['00',10,20,30,40,50]
var thisYear = date.getFullYear();
var thisMon = date.getMonth();
var thisDay = date.getDate();
var thisHour = date.getHours();
var thisMinutes = date.getMinutes();
var nextYear = thisYear+1;
for (let i = thisYear; i <= date.getFullYear()+1; i++) {
  years.push(i)
}
for (let i = date.getMonth(); i <= 11; i++) {
  var k = i;
  if (0 <= i && i < 9) {
    k = "0" + (i + 1);
  } else {
    k = (i + 1);
  }
  months.push(k)
}

if (0 <= thisMon && thisMon < 9) {
  thisMon = "0" + (thisMon + 1);
} else {
  thisMon = (thisMon + 1);
}

if (0 <= thisDay && thisDay < 10) {
  thisDay = "0" + thisDay;
}

var totalDay = mGetDate(date.getFullYear(), thisMon);
for (let i = 1; i <= 31; i++) {
  var k = i;
  if (0 <= i && i < 10) {
    k = "0" + i
  }
  days.push(k)
}

/*for (let i = 0; i <= 23; i++) {
  var k = i;
  if (0 <= i && i < 10) {
    k = "0" + i
  }
  hours.push(k)
}*/
// for (let i = 0; i <= 59; i++) {
//   var k = i;
//   if (0 <= i && i < 10) {
//     k = "0" + i
//   }
//   minutes.push(k)
// }
function mGetDate(year, month) {
  var d = new Date(year, month, 0);
  return d.getDate();
}


//判断是否选择时间成功的字段
var isOk= false;
Page({
  data: {
    http_service: http_service,
    array:[],
    years: years,
    year: date.getFullYear(),
    months: months,
    month: thisMon,
    days: days,
    day: thisDay,
    hours: ['8:30','9:00', '9:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30',
      '13:00', '13:30', '14:00', '14:30', '15:00', '15:30', '16:00',
      '16:30', '17:00', '17:30', '18:00','18:30','19:00'],
    value: [0, 0, thisDay - 1, 0, 0],
    date: date.getFullYear() + '-' + thisMon + '-' + thisDay  ,
    //是传过来的参数
    store_id: 0,
    store_name: '',
    service_id: 0,
    service_name: '',
    price: 0,
    tec_id:0,
    //选择的时间和区间
    c_date: date.getFullYear() + '-' + thisMon + '-' + thisDay ,
    c_time:"8:30",
    //样式的两种
    itemId:0,
  
  },
  onLoad:function(options){
      var that = this;
      //console.log(options.tec_id)
      this.setData({
        store_id: options.storeId,
        service_id: options.serviceId,
        price: options.price,
        tec_id : options.tec_id
      })
  },

  bindChange: function (e) {
    var that = this;
    const val = e.detail.value
    this.setData({
      year: this.data.years[val[0]],
      month: this.data.months[val[1]],
      day: this.data.days[val[2]],
      date: this.data.years[val[0]] + '-' + this.data.months[val[1]] + '-' + this.data.days[val[2]],
      c_date: this.data.years[val[0]] + '-' + this.data.months[val[1]] + '-' + this.data.days[val[2]],
      c_time: this.data.hours[val[3]],
      itemId:0,
    })
  },

  /**
   * 点击选取时间
   */
  select:function(e){
    var that = this;

    that.setData({
      c_time:e.currentTarget.id,
      itemId: e.currentTarget.id,
    })
  },


  cheack: function () {
    var that = this;
    
    if (that.data.c_time == 0){
      wx.showModal({
        title: '未选择预约时间',
        content: '请选择您需要预约的时间！',
      })
    }else{
      wx.setStorage({
        key: 'affirm',
        data: {
          storeId: that.data.store_id,
          serviceId: that.data.service_id,
          price: that.data.price,
          tec_id: 0,
          date: that.data.c_date + ' ' + that.data.c_time + '点',
          c_date: that.data.c_date,
          c_time: that.data.c_time,
        },
        success: function () {
          wx.navigateBack({
            delta: 1
          })
        }
      })
    }

   
  }




})  